package top.laoliu.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import top.laoliu.mapper.UserMapper;
import top.laoliu.pojo.User;
import top.laoliu.service.UserService;

/**
 * @Author: acer
 * @Date: 2020/10/7 20:13
 * @Description:
 */
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public int insertUser(User user) {
        return userMapper.insertUser(user);
    }

    @Override
    public int deleteUser(Integer user_id) {
        return userMapper.deleteUser(user_id);
    }

    @Override
    public boolean isExistUser(String email, String phone) {
        User userByEmail = userMapper.getUserByEmail(email);
        User userByPhone = userMapper.getUserByPhone(phone);
        if (userByEmail == null && userByPhone == null) {
            return false;
        }
        return true;
    }

    @Override
    public User getUserById(Integer user_id) {
        return userMapper.getUserById(user_id);
    }

    @Override
    public User getUserByEmail(String email) {
        return userMapper.getUserByEmail(email);
    }

    @Override
    public boolean userLogin(String email, String password) {
        User user = userMapper.userLogin(email, password);
        if (user == null) {
            return false;
        }
        return true;
    }

    @Override
    public int updateUser(User user) {
        return userMapper.updateUser(user);
    }
}
